#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int aa[N],a[N],q[N],g[30][N],x[5],win[30][N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	int n,m;
	cin >> n >> m;
	for (int i = 1;i <= n;i++)
		cin >> aa[i];
	for (int i = 1;i <= m;i++)
		cin >> q[i];
	for (int i = 1;i <= log2(n) + 1;i++)
	{
		string s;
		cin >> s;
		for (int j = 0;j < (int)s.size();j++)
			g[i][j] = s[i] - '0';
	}
	int t;
	cin >> t;
	for (;t > 0;t--)
	{
		for (int i = 0;i < 4;i++)
			cin >> x[i];
		for (int i = 1;i <= n;i++)
			a[i] = aa[i] ^ x[i % 4];
		cout << 0 << endl;
	}
	return 0;
}
